import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class CommentWidget extends StatelessWidget {
  List<dynamic> comments = [];

  CommentWidget(this.comments, {super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: List.generate(comments.length, (index) {
          return Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                alignment: Alignment.bottomLeft,
                child: Row(
                  children: [
                    const Padding(
                      padding: EdgeInsets.all(10),
                      child: CircleAvatar(
                        radius: 20,
                        backgroundImage: NetworkImage(
                            "https://img1.baidu.com/it/u=2327718586,410319763&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"),
                      ),
                    ),
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          comments[index]['name'],
                          textAlign: TextAlign.left,
                        ),
                        Text(comments[index]["time"] + "  回复",
                            style: const TextStyle(
                                fontSize: 12, color: Colors.grey)),
                      ],
                    ),
                  ],
                ),
              ),
              Padding(
                padding: const EdgeInsets.fromLTRB(60, 0, 0, 0),
                child: Text(comments[index]['content']),
              ),
              // ReplyComment(comments[index])
            ],
          );
        }));
  }

  ReplyComment(comment) {
    if (comment['replyContent'] != null) {
      return ListView.builder(
          itemCount: comment['replyContent'].length,
          itemBuilder: (context, index2) {
            return Column(
              children: [
                Container(
                  alignment: Alignment.bottomLeft,
                  child: Row(
                    children: [
                      const Padding(
                        padding: EdgeInsets.all(10),
                        child: CircleAvatar(
                          radius: 20,
                          backgroundImage: NetworkImage(
                              "https://img1.baidu.com/it/u=2327718586,410319763&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"),
                        ),
                      ),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: const [
                          const Text(
                            "nava 5 Pro",
                            textAlign: TextAlign.start,
                          ),
                          const Padding(
                            padding: EdgeInsets.all(5),
                            child: Text("2023-3-01 11:10   回复",
                                style: const TextStyle(
                                    fontSize: 12, color: Colors.grey)),
                          ),
                        ],
                      )
                    ],
                  ),
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(60, 0, 0, 0),
                  child: Text("这偏博客写的很不错啊，看着受益很大"),
                ),
              ],
            );
          });
    }
  }
}
